<!DOCTYPE html>
<html lang="zh">
<head>
    <base href="${base}/">
    <meta charset="UTF-8" />
    <title>表单信息</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport"/>
    <meta content="IE=Edge" http-equiv="X-UA-Compatible" />
    <!--<link href="amis/sdk.css" rel="stylesheet" />-->
    <link href="amis/antd.css" rel="stylesheet" />
    <!-- 从 1.1.0 开始 sdk.css 将不支持 IE 11，如果要支持 IE11 请引用这个 css，并把前面那个删了 -->
    <!--<link rel="stylesheet" href="amis/sdk-ie11.css" /> -->
    <!-- 不过 amis 开发团队几乎没测试过 IE 11 下的效果，所以可能有细节功能用不了，如果发现请报 issue -->

    <!--    <link href="amis/cxd.css" rel="stylesheet" />-->
    <!--    <link href="amis/dark.css" rel="stylesheet" />-->
    <!--    <link href="amis/antd.css" rel="stylesheet" />-->

    <style>
        html, body, .app-wrapper {
            position: relative;
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div class="app-wrapper" id="root"></div>
<script src="amis/sdk.js"></script>
<script src="jquery.min.js"></script>
<script type="text/javascript">
    (function () {
        getMainData()
    })();

    function getMainData() {
        let amis = amisRequire('amis/embed');
        // 通过替换下面这个配置来生成不同页面
        let amisJSON = {
            // "title": "支持多层嵌套，列数据中有 children 字段即可。（建议不超过10层）",
            "body": {
                "type": "crud",
                // "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/crud/table2",
                "api": "/fmBase",
                "saveOrderApi": "/fmBase",
                "expandConfig": {
                    "expand": "first",
                    "accordion": true
                },
                // 一次性加载（取消分页）
                "loadDataOnce": false,
                // false 排序不会刷新
                "syncLocation": false,
                // 取消固定表头
                "affixHeader": false,
                "draggable": false,
                "columns": [
                    {
                        "name": "id",
                        "label": "ID",
                        "sortable": true,
                        "type": "text",
                        "toggled": true,
                        "width": 100
                    },
                    {
                        "name": "name",
                        "label": "表单名称",
                        "sortable": true,
                        "searchable": true,
                        "type": "text",
                        "toggled": true
                    },
                    {
                        "name": "tableCode",
                        "label": "物理表代码",
                        "sortable": true,
                        "type": "text",
                        "toggled": true
                    },
                    {
                        "name": "version",
                        "label": "版本号",
                        "quickEdit": true,
                        "type": "text",
                        "toggled": true
                    },
                    {
                        "type": "operation",
                        "label": "操作",
                        "width": 100,
                        "buttons": [
                            {
                                "type": "button",
                                "icon": "fa fa-eye",
                                "actionType": "dialog",
                                "dialog": {
                                    "title": "查看",
                                    "body": {
                                        "type": "form",
                                        "body": [
                                            {
                                                "type": "static",
                                                "name": "name",
                                                "label": "表单名称"
                                            },
                                            {
                                                "type": "divider"
                                            },
                                            {
                                                "type": "static",
                                                "name": "tableCode",
                                                "label": "物理表代码"
                                            },
                                            {
                                                "type": "divider"
                                            },
                                            {
                                                "type": "static",
                                                "name": "version",
                                                "label": "版本号"
                                            }
                                        ]
                                    }
                                }
                            },
                            {
                                "type": "button",
                                "icon": "fa fa-pencil",
                                "actionType": "drawer",
                                "drawer": {
                                    "position": "left",
                                    "size": "lg",
                                    "title": "编辑",
                                    "body": {
                                        "type": "form",
                                        "name": "sample-edit-form",
                                        "api": "/fmBase/$id",
                                        "body": [
                                            {
                                                "type": "input-text",
                                                "name": "name",
                                                "label": "表单名称",
                                                "required": true
                                            },
                                            {
                                                "type": "divider"
                                            },
                                            {
                                                "type": "input-text",
                                                "name": "tableCode",
                                                "label": "物理表代码",
                                                "required": true
                                            },
                                            {
                                                "type": "divider"
                                            },
                                            {
                                                "type": "input-text",
                                                "name": "version",
                                                "label": "版本号"
                                            }
                                        ]
                                    }
                                }
                            },
                            {
                                "type": "button",
                                "icon": "fa fa-times text-danger",
                                "actionType": "ajax",
                                "confirmText": "您确认要删除?",
                                "api": "delete:/fmBase/$id",
                                "reload": "none"
                            },
                            {
                                // "label": "设计",
                                "type": "button",
                                "icon": "fa fa-pencil text-danger",
                                // "level": "link",
                                // "actionType": "url",
                                // "blank": "true",
                                // "size": "xs",
                                // "url": "http://localhost:3000?id=$id"
                                "onClick": "customAction(props)"
                            }
                        ],
                        "toggled": true
                    }
                ]
            }
        }

        amis.embed('#root', amisJSON, { theme: 'antd' });
    }

    function customAction(props) {
        console.log(props)
        // localStorage.setItem('formily-schema', props.data.formData)
        // document.cookie = 'formily-schema=' + props.data.formData
        window.postMessage("Hello！", "http://localhost:3000")
        const win = window.open('http://localhost:3000?id=' + props.data.id)
        console.log('domain', win.domain)
    }
</script>
</body>
</html>
